iT邦幫忙

2023 iThome 鐵人賽

DAY 20
0
Software Development

Womanium Global Quantum Project-Quantum Software&Hardware系列 第 20

Day20->E91 Protocol Attack & Security

  • 分享至 

  • xImage
  •  

E91協議的安全性

當量子位元從合法用戶傳輸時,Espian 無法從量子位元中獲取任何訊息,因為其中沒有編碼訊息。
只有在 Asja 和 Balvis 進行測量後,資訊才會「產生」。

然而,通常實現 E91 的方式是與設備獨立的方式,意思就是其中EPR 對的來源由第三方(Charlie) 控制,第三方生成糾纏量子位對並將一個量子位元發送給Asja,將第二個量子位元發送給Balvis。

反向策略:Man-in-the-middle attack on E91

如果 E91 作為設備獨立協議實現,Espian 可以使用中間人策略並在通往 Asja 和 Balvis 的途中攔截兩個量子位元!

他可以測量 EPR 對中的兩個量子位元並用假狀態替換它們(|00⟩或者|11⟩)

Espian 應使用哪些測量基準?

據我們所知,Asja 正在使用𝑍, 𝑋, 𝑊 bases (θ_A), Balvis 使用𝑍, 𝑊, 𝑉 bases(θ_B)
取得密鑰位的回合為: https://ithelp.ithome.com.tw/upload/images/20231005/201373944D1qTkRXLt.pnghttps://ithelp.ithome.com.tw/upload/images/20231005/20137394kvskG00U41.png

剩餘回合用於測試 CHSH 不等式。
因此,Espian 只需要使用這些base!

步驟 1:分配量子態

  1. Charlie 準備了 64 對 EPR 送給 Asja 和 Balvis。
  2. Espian 攔截量子位並使用以下方法測量每一對 𝑍𝑍或者 𝑊𝑊base。他隨機且獨立地決定每對使用哪些base。
  3. Espian 準備假狀態並將其發送給 Asja 和 Balvis(|00⟩或者 |11⟩,取決於他的測量結果)。
  4. Asja 隨機選擇測量base ( 𝑍, 𝑋或者 𝑊)並測量第一個量子位元(qreg[0])。
  5. Balvis 隨機選擇測量base( 𝑍, 𝑊或者 𝑉)並測量第二個量子位元(qreg[1])。

所有用戶都會保存他們為每回合選擇的base的資訊。

# import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from random import randrange

#Registers for measurement bases and keys
basesAsja, keyAsja = [],[]
basesBalvis, keyBalvis = [],[]
basesEspian, keyEspian = [],[]

for i in range(64): #Charlie prepares 64 EPR pairs
    qreg = QuantumRegister(2)
    creg = ClassicalRegister(2) 
    mycircuit = QuantumCircuit(qreg, creg)

    #Creating entanglement
    mycircuit.h(qreg[0])
    mycircuit.cx(qreg[0], qreg[1])

    #Espian intercepts qubits and chooses measurement basis
    choiceEspian=randrange(2)
    if choiceEspian==0:#measurement in Z basis
        basesEspian.append('Z')
    if choiceEspian==1:#measurement in W basis
        mycircuit.s(qreg)
        mycircuit.h(qreg)
        mycircuit.t(qreg)
        mycircuit.h(qreg)
        basesEspian.append('W')
    
    mycircuit.measure(qreg,creg) #applying final measurement
    job = execute(mycircuit,Aer.get_backend('qasm_simulator'),shots=1)
    counts = job.result().get_counts(mycircuit)

    #Saving results
    result=list(counts.keys())[0] #retrieve key from dictionary
    keyEspian.append(int(result[0])) #saving first qubit value in Espian's key register 
for i in keyEspian:#Espian preparing fake states
    qregE = QuantumRegister(2)
    cregE = ClassicalRegister(2) 
    mycircuitE = QuantumCircuit(qregE, cregE)
    if keyEspian=='1': #if Espian obtained result 11 or 00, she will send corresponding states to Asja and Balvis
        mycircuitE.x(qregE[0])
        mycircuitE.x(qregE[1])
    if keyEspian=='0':
        pass #preparing state 00
       
#Asja chooses measurement basis
    choiceAsja=randrange(3)
    if choiceAsja==0:#measurement in Z basis
        basesAsja.append('Z')
    if choiceAsja==1:#measurement in X basis
        mycircuitE.h(qregE[0])
        basesAsja.append('X')
    if choiceAsja==2:#measurement in W basis
        mycircuitE.s(qregE[0])
        mycircuitE.h(qregE[0])
        mycircuitE.t(qregE[0])
        mycircuitE.h(qregE[0])
        basesAsja.append('W')

#Balvis chooses measurement basis
    choiceBalvis=randrange(3)
    if choiceBalvis==0:#measurement in Z basis
        basesBalvis.append('Z')
    if choiceBalvis==1:#measurement in W basis
        mycircuitE.s(qregE[1])
        mycircuitE.h(qregE[1])
        mycircuitE.t(qregE[1])
        mycircuitE.h(qregE[1])
        basesBalvis.append('W')
    if choiceBalvis==2:#measurement in V basis
        mycircuitE.s(qregE[1])
        mycircuitE.h(qregE[1])
        mycircuitE.tdg(qregE[1])
        mycircuitE.h(qregE[1])
        basesBalvis.append('V')

    mycircuitE.measure(qregE,cregE) #applying final measurement
    job = execute(mycircuitE,Aer.get_backend('qasm_simulator'),shots=1)
    countsE = job.result().get_counts(mycircuitE)
        
    #Saving results
    resultE=list(countsE.keys())[0] #retrieve key from dictionary
    keyAsja.append(int(resultE[0])) #saving first qubit value in Asja's key register 
    keyBalvis.append(int(resultE[1])) #and second to Balvis

第 2 步:Sifting

Asja 和 Balvis 使用經典通道比較base。他們將關鍵字串分為兩組——測量base匹配的組和base不匹配的組。它們儲存有關base的資訊並獲得base不匹配的回合的位元。
Espian傾聽他們的交流,並繼續他與Asja 和 Balvis相同的測量base的回合。

#Registers
finalKeyAsja, finalKeyBalvis = [],[] #for matching rounds
finalKeyEspian=[] #for matching rounds
diffAsja, diffBalvis = [],[] #missmatched rounds
diffBasesA, diffBasesB = [],[] #bases of missmatched rounds
#Users comparing rounds
for i in range(0, len(basesAsja)):
    if basesAsja[i] == basesBalvis[i]: #When users used same bases
        finalKeyAsja.append(keyAsja[i])
        finalKeyBalvis.append(keyBalvis[i]) 
    else: #When used different
        diffAsja.append(keyAsja[i])
        diffBalvis.append(keyBalvis[i])
        diffBasesA.append(basesAsja[i])
        diffBasesB.append(basesBalvis[i])

    if (basesAsja[i] == basesEspian[i] and basesBalvis[i] == basesEspian[i]):
        finalKeyEspian.append(keyEspian[i])

此時,我們可以知道Espianc獲得多少比例的密鑰

key_percent_Espian = (len(finalKeyAsja) - len(finalKeyEspian))/len(finalKeyAsja) # Espian's knowledge
print(key_percent_Espian)

0.5

步驟3:CHSH inequality violation test

#ZW
sameZW = 0
diffZW = 0
for i, (bA, bB) in enumerate(zip(diffBasesA, diffBasesB)):
    if (bA == 'Z' and bB == 'W'):
        if diffAsja[i]==diffBalvis[i]:
            sameZW=sameZW+1
        else:
            diffZW=diffZW+1

            
totalZW=sameZW+diffZW
if totalZW!=0:
    ZW=(sameZW-diffZW)/totalZW
else:
    ZW=0
    
#XW
sameXW = 0
diffXW = 0
for i, (bA, bB) in enumerate(zip(diffBasesA, diffBasesB)):
    if (bA == 'X' and bB == 'W'):
        if diffAsja[i]==diffBalvis[i]:
            sameXW=sameXW+1
        else:
            diffXW=diffXW+1

totalXW=sameXW+diffXW
if totalXW!=0:
    XW=(sameXW-diffXW)/totalXW
else:
    XW=0

#XV
sameXV = 0
diffXV = 0
for i, (bA, bB) in enumerate(zip(diffBasesA, diffBasesB)):
    if (bA == 'X' and bB == 'V'):
        if diffAsja[i]==diffBalvis[i]:
            sameXV=sameXV+1
        else:
            diffXV=diffXV+1

totalXV=sameXV+diffXV
if totalXV!=0:
    XV=(sameXV-diffXV)/totalXV
else:
    XV=0
    
#ZV
sameZV = 0
diffZV = 0
for i, (bA, bB) in enumerate(zip(diffBasesA, diffBasesB)):
    if (bA == 'Z' and bB == 'V'):
        if diffAsja[i]==diffBalvis[i]:
            sameZV=sameZV+1
        else:
            diffZV=diffZV+1

totalZV=sameZV+diffZV
if totalZV!=0:
    ZV=(sameZV-diffZV)/totalZV

else:
    ZV=0
    
S=ZW+XW-XV+ZV

print("CHSH inequality value is", S)

CHSH inequality value is 1.5595238095238093

由於Espian對金鑰分配過程的干擾,CHSH不等式值遠小於https://ithelp.ithome.com.tw/upload/images/20231005/20137394kFYDS33SI6.png

透過這種方式,使用者可以確定他們的通訊是否受到損害,並且可以中止協議。

Espian可能會嘗試用自己準備的數據來誤導Asja和Balvis,但他不知道他們會選擇哪些測量基礎,因此行不通。

但現在會產生一個問題, Asja 和 Balvis 的最終密鑰不匹配!

print(finalKeyAsja)
print(finalKeyBalvis)

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]

這種不匹配的原因是因為 Asja & Balvis 用𝑊𝑊進行測量。
Espian使用 |00⟩ 和 |11⟩作為假的量子狀態。
因此當 Asja 和 Balvis 用𝑊-base測量這些狀態時,他們會得到機率結果。

#Preparing state 00
qregT = QuantumRegister(2)
cregT = ClassicalRegister(2) 
mycircuitTest = QuantumCircuit(qregT, cregT)

#Measuring in W-basis
mycircuitTest.s(qregT)
mycircuitTest.h(qregT)
mycircuitTest.t(qregT)
mycircuitTest.h(qregT)

mycircuitTest.measure(qregT,cregT)

job = execute(mycircuitTest,Aer.get_backend('qasm_simulator'),shots=100)
counts = job.result().get_counts(mycircuitTest)
print(counts) # counts is a dictionary

{'00': 67, '10': 15, '01': 14, '11': 4}

因此Asja & Balvis的量子位變成疊加態。

參考資料: womanium 教材


上一篇
Day19->E91 Protocol implement
下一篇
Day21->Before Error Correction
系列文
Womanium Global Quantum Project-Quantum Software&Hardware30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言